/**
 * @description  : 字典单选
 * @descriptionDetail : 字典单选
 * @copyright    : 浙江烟草
 * @author       : mc
 * @create       : 2022-10-03 17:09:11
 */
<template>
  <view style="width: 100%;">
    <u-radio-group v-bind="$attrs" v-model="mVal" @change="radioGroupChange">
      <u-radio
        shape="circle"
        :name="item.value"
        v-for="(item, index) in radioList"
        :key="index" 
        v-model="item.checked"
      >
        {{ item.label }}
      </u-radio>
    </u-radio-group>
  </view>
</template>
<script>
export default {
  props: {
    value: {
      type: String | Number,
      default: ''
    },
    dictType: {     // 字典类型
      type: String,
      default: ""
    },
    extFilterFun:{
      type: Function,
      default: (itm, keyWords) => { // 字典单个对象， 字典keyword
        return true;
      }
    },
  },
  data() {
    return {
      mVal: this.value,
      radioList: []
    }
  },
  watch: {
    dictType: {
      immediate: true,
      handler(v) {
        this.radioList = this.$u.dic.getByDictCode(v);
        this.radioList = this.radioList.filter(itm => {
          return this.extFilterFun(itm, v);
        })
      }
    },
    value:{
      immediate: false,
      handler(v) {
        this.mVal = v;
      }
    }
  },
  created () {
    if (this.dictType) {
      this.radioList = this.$u.dic.getByDictCode(this.dictType);
      this.radioList = this.radioList.filter(itm => {
        return this.extFilterFun(itm, this.dictType);
      })
    }
  },
  methods: {
    radioGroupChange(arg) {
      this.$emit("input", arg);
    },
  },
}
</script>